#此程序存在几个问题，当第一次查看购买信息时，不会显示内容；

user_table = {"lzw":"123456","lzc":"6688"}
goods_name = {'001':'斯伯丁篮球','002':'安慕希酸奶','003':'德芙巧克力','004':'养乐多'}
goods_price = {'001':168,'002':68,'003':35,'004':12}

buy = {}
buy = [{"001":3},{"002":5}]

def log_test(name,passwd):
    user = (name,passwd)
    if user in user_table.items():
        return True
    else:
        return False

def shopping_system(budget):
    while True:
        num = input("查看商品信息请输入1,查看已购买信息请输入2,购买商品请输入3:")
        if num == "1":
            for i,j in goods_name.items():
                print(f"编号{i},商品是{j},价格是{goods_price[i]}")
        elif num == "2":
            for i,j in buy.items():
                print(f"购买了{i},花费了{j}元")
        elif num == "exit":
            for i in buy:
                print(f"已购买商品{i},余额{budget}")
            break
        elif num == "3":
            num1 = input("请输入购买商品的编号：")
            if num1 in goods_price:
                if budget >= goods_price[num1]:
                    budget -= goods_price[num1]
                    buy[goods_name[num1]] = goods_price[num1]
                    print(f"您已成功购买编号{num1}商品")
                else:
                    print("余额不足，请充值")
            elif num1 == "exit":
                for i in buy:
                    print(f"已购买商品{i},余额{budget}")
                break
            else:
                print("输入商品的编号有误")
        else:
            print("输入编号有误，请重新输入")

while True:
    print("退出请输入exit")
    name = input("请输入用户名：")
    passwd = input("请输入密码：")
    if log_test(name,passwd):
        print("欢迎进入三乐购物系统")
        while True:
            budget = input("请输入你的预算(必须是整数):")
            if budget.isdigit():
                shopping_system(int(budget))
                prompt = "exit"
                break
            elif budget == "exit":
                break
            else:
                print("输入的预算有错误，请重新输入")
        if prompt == "exit":
            print("已退出三乐购物系统")
            break

        if budget == "exit":
            print("已退出三乐购物系统")
            break
    elif name == "exit" or passwd == "exit":
        print("退出登陆系统")
        break
    else:
        print("用户名密码输入错误，请重新输入")






